package com.zl.tby.vo;

import com.zl.tby.core.base.util.ToolsUtil;
import com.zl.tby.model.TbyCategoryDict;
import com.zl.tby.model.TbyResearchActivities;
import lombok.Data;
import org.noear.solon.validation.annotation.Length;
import org.noear.solon.validation.annotation.NotBlank;
import org.noear.solon.validation.annotation.NotNull;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * 科研活动调查管理
 * @author changpeng
 * @version 1.0
 * @since 2024/8/6 20:12
 */
@Data
public class TbyResearchActivitiesForm {
    /**主键id*/
    private Long id;
    /**活动名称*/
    @NotBlank(message = "活动名称不能为空")
    @Length(max = 20, message = "活动名称最大长度为20")
    private String name;
    /**活动种类*/
    @NotNull(message = "活动种类不能为空")
    private Long categoryId;
    /**活动类型*/
    @NotNull(message = "活动类型不能为空")
    private Long typeId;
    /**活动时间*/
    @NotNull(message = "活动时间不能为空")
    private Date holdDate;
    /**活动地点*/
    @Length(max = 200, message = "活动地点最大长度为200")
    private String address;
    /**活动内容*/
    private String content;
    /**经度*/
    @NotBlank(message = "经度不能为空")
    @Length(max = 32, message = "经度最大长度为32")
    private String longitude;
    /**纬度*/
    @NotBlank(message = "纬度不能为空")
    @Length(max = 32, message = "纬度最大长度为32")
    private String latitude;

    private String categoryName;
    private String typeName;
    private String holdDateFormat;
    
    public TbyResearchActivities createEntity() {
        TbyResearchActivities entity = new TbyResearchActivities();
        entity.setId(this.getId());
        entity.setName(this.getName());
        entity.setCategoryId(this.getCategoryId());
        entity.setTypeId(this.getTypeId());
        entity.setHoldDate(this.getHoldDate());
        entity.setAddress(this.getAddress());
        entity.setContent(this.getContent());
        entity.setLongitude(this.getLongitude());
        entity.setLatitude(this.getLatitude());
        return entity;
    }

    public void updateEntity(TbyResearchActivities entity) {
        entity.setName(this.getName());
        entity.setCategoryId(this.getCategoryId());
        entity.setTypeId(this.getTypeId());
        entity.setHoldDate(this.getHoldDate());
        entity.setAddress(this.getAddress());
        entity.setContent(this.getContent());
        entity.setLongitude(this.getLongitude());
        entity.setLatitude(this.getLatitude());
    }

    public static TbyResearchActivitiesForm recordConvert(TbyResearchActivities entity, Map<Long, TbyCategoryDict> dictMap) {
        TbyResearchActivitiesForm form = new TbyResearchActivitiesForm();
        form.setId(entity.getId());
        form.setName(entity.getName());
        form.setCategoryId(entity.getCategoryId());
        if (dictMap.containsKey(entity.getCategoryId())) {
            form.setCategoryName(dictMap.get(entity.getCategoryId()).getName());
        }
        form.setTypeId(entity.getTypeId());
        if (dictMap.containsKey(entity.getTypeId())) {
            form.setTypeName(dictMap.get(entity.getTypeId()).getName());
        }
        form.setHoldDate(entity.getHoldDate());
        if (form.getHoldDate() != null) {
            form.setHoldDateFormat(ToolsUtil.dateUtil2String(form.getHoldDate(), "yyyy-MM-dd"));
        }
        form.setLongitude(entity.getLongitude());
        form.setLatitude(entity.getLatitude());
        return form;
    }
}
